﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
using BussinessLogic;

namespace ATMSystem_G5_HaUI.UC4
{
    public partial class GridViewControl : System.Web.UI.UserControl
    {
        ViewHistoryLogic clsviewhistorylogic = new ViewHistoryLogic();
        protected void Page_Load(object sender, EventArgs e)
        {
            loadgridview();
        }
        public void loadgridview()
        {
            try
            {
                string chooseitem = Session["chooseitem"].ToString();
                string CardNo = Session["CardNo"].ToString();
                switch (chooseitem)
                {
                    case "7 day":

                        grdviewhistory.DataSource = clsviewhistorylogic.loadView(CardNo, 7);
                        grdviewhistory.DataBind();
                        break;
                    case "30 day":
                        grdviewhistory.DataSource = clsviewhistorylogic.loadView(CardNo, 30);
                        grdviewhistory.DataBind();
                        break;
                    case "120 day":
                        grdviewhistory.DataSource = clsviewhistorylogic.loadView(CardNo, 120);
                        grdviewhistory.DataBind();
                        break;
                    case "180 day":
                        grdviewhistory.DataSource = clsviewhistorylogic.loadView(CardNo, 180);
                        grdviewhistory.DataBind();
                        break;
                    case "360 day":
                        grdviewhistory.DataSource = clsviewhistorylogic.loadView(CardNo, 360);
                        grdviewhistory.DataBind();
                        break;
                    case "720 day":
                        grdviewhistory.DataSource = clsviewhistorylogic.loadView(CardNo, 720);
                        grdviewhistory.DataBind();
                        break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
        protected void btn3_Click(object sender, EventArgs e)
        {
            try
            {
                grdviewhistory.PageIndex -= 1;
                grdviewhistory.DataBind();
                loadgridview();
            }
            catch
            {
            }
        }

        protected void btn6_Click(object sender, EventArgs e)
        {
            try
            {
                grdviewhistory.PageIndex += 1;
                grdviewhistory.DataBind();
                loadgridview();
            }
            catch
            {
            }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Session["CardNo"] = null;
            Response.Redirect("~/Home.aspx");
        }

        protected void grdviewhistory_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            int NewPage;
            NewPage = e.NewPageIndex;
            if (NewPage < 0 || NewPage >= grdviewhistory.PageCount)
            {
                e.Cancel = true;
            }
            else
            {
                grdviewhistory.PageIndex = NewPage;
                grdviewhistory.DataBind();
            }
            loadgridview();
        }
    }
}